from rest_framework import serializers
from user import models
import re

def func1(value):
    if value.len() == 11:
        return value
    else:
        raise serializers.ValidationError("手机号需11位数")



class Phonenumser(serializers.ModelSerializer):
    class Meta:
        model = models.Phonenum
        fields = "__all__"
        extra_kwargs = {"phone":{"validators":[func1]}}
